package com.andaily.domain.dto.account;

import com.andaily.domain.shared.paginated.DefaultPaginated;
import com.andaily.domain.shared.security.SecurityUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Shengzhao Li
 */
public class AccountSearchResultDTO extends DefaultPaginated<AccountDTO> {
    /**
     * The search conditions
     */
    private AccountSearchDTO accountSearch;
    /**
     * The search total amount
     */
    private BigDecimal totalAmount;

    private boolean showMore = true;

    /**
     * Default constructor
     */
    public AccountSearchResultDTO() {
    }

    public AccountSearchResultDTO(AccountSearchDTO accountSearchDTO) {
        this();
        this.accountSearch = accountSearchDTO;
        int number = accountSearchDTO.getPageNumber();
        if (number != 0) {
            this.setPageNumber(number);
            this.setTotalSize(accountSearchDTO.getTotalSize());
        }
    }

    public Map<String, Object> queryParamMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("prePageSize", getPerPageSize());
        map.put("startIndex", getStartIndex());
        map.put("ownerGuid", SecurityUtils.currentUserGuid());

        accountSearch.addQueryParams(map);
        return map;
    }

    public void updateShowMore() {
        this.showMore = isHasNext();
    }

    public AccountSearchDTO getAccountSearch() {
        return accountSearch;
    }

    public void setAccountSearch(AccountSearchDTO accountSearch) {
        this.accountSearch = accountSearch;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public boolean isShowMore() {
        return showMore;
    }

    public void setShowMore(boolean showMore) {
        this.showMore = showMore;
    }
}
